const host = "http://120.79.244.56:8088/"

//用户
function login() {
    $.ajax({
        type: "post",
        url: host + "user/login.do",
        data: {
            username: $("#username").val(),
            password: $("#password").val()
        },
        xhrFields: {
            withCredentials: true
        },
        success: function (jackson) {
            if (jackson.status == 1) {
                $("#login-msg").html(jackson.msg);
                $("#model-logon").modal('open');
            } else if (jackson.status == 0) {
                window.location.href = "index.html"
            }
        }
    })
}

function register(username, password, sex, age, phone, address) {
    $.ajax({
        type: "post",
        url: host + "user/register.do",
        data: {
            username: username,
            password: password,
            sex: sex,
            age: age,
            phone: phone,
            address: address
        },
        xhrFields: {
            withCredentials: true
        },
        success: function (jackson) {
            if (jackson.status == 1) {
                alert(jackson.msg)
            } else if (jackson.status == 0) {
                window.location.href = "login.html"
            }
        }
    })
}

function checkValid(username) {
    let msg = "";
    $.ajax({
        type: "post",
        url: host + "user/check_valid.do",
        data: {
            username: username
        },
        async: false,
        xhrFields: {
            withCredentials: true
        },
        success: function (jackson) {
            msg = jackson.status;
        }
    });
    return msg;
}

function getUserInfo() {
    $.ajax({
        type: "post",
        url: host + "user/get_user_info.do",
        xhrFields: {
            withCredentials: true
        },
        async: false,
        success: function (jackson) {
            if (jackson.status == 1) {
                window.location.href = "login.html";
            } else if (jackson.status == 0) {
                $("#userName").html(jackson.data.username);

                $(".username").html(jackson.data.username);
                $(".sex").html(jackson.data.sex);
                $(".age").html(jackson.data.age);
                $(".phone").html(jackson.data.phone);
                $(".address").html(jackson.data.address);

                $("#btnLoginOut").append(
                    "<button type=\"button\" onclick=\"loginOut()\" class=\"am-btn am-btn-warning\" style=\"width: 100%;border-radius: 10px;outline: none\">退出登录</button>\n"
                )

                $(".phone").val(jackson.data.phone);
                $(".address").val(jackson.data.address);
                $("#btnUpdateInfo").append(
                    "<button type=\"button\" id='updateBtn' disabled='' class=\"am-btn am-btn-secondary\" style=\"width: 100%;border-radius: 10px;outline: none;\">立即修改</button>\n"
                )
            }
        }
    });
}

function forgetPwd(phone) {
    $.ajax({
        type: "post",
        url: host + "user/forget_pwd.do",
        data: {
            phone: phone
        },
        xhrFields: {
            withCredentials: true
        },
        success: function (jackson) {
            if (jackson.status == 1) {
                alert(jackson.msg)
            } else if (jackson.status == 0) {

            }
        }
    })
}

function forgetResetPassword(username, phone, passwordNew, code) {
    $.ajax({
        type: "post",
        url: host + "user/forget_reset_password.do",

        data: {
            username: username,
            phone: phone,
            passwordNew: passwordNew,
            code: code
        },
        xhrFields: {
            withCredentials: true
        },
        success: function (jackson) {
            if (jackson.status == 1) {
                alert(jackson.msg)
            } else if (jackson.status == 0) {
                window.location.href = "login.html"
            }
        }
    })
}

function resetPassword(passwordOld, passwordNew) {
    $.ajax({
        type: "post",
        url: host + "user/reset_password.do",

        data: {
            passwordOld: passwordOld,
            passwordNew: passwordNew
        },
        xhrFields: {
            withCredentials: true
        },
        success: function (jackson) {
            if (jackson.status == 1) {
                alert(jackson.msg)
            } else if (jackson.status == 0) {
                window.location.href = "login.html"
            }
        }
    })
}

function updateInformation(phoneNew, addressNew) {
    let msg = ""
    $.ajax({
        type: "post",
        url: host + "user/update_information.do",
        data: {
            phone: phoneNew,
            address: addressNew
        },
        async: false,
        xhrFields: {
            withCredentials: true
        },
        success: function (jackson) {
            msg = jackson.status ? jackson.msg : jackson.data;
        }
    });
    return msg;
}

function loginOut() {
    $.ajax({
        type: "post",
        url: host + "user/loginOut.do",
        xhrFields: {
            withCredentials: true
        },
        success: function (jackson) {
            if (jackson.status == 1) {
                alert(jackson.msg)
            } else if (jackson.status == 0) {
                window.location.href = "login.html"
            }
        }
    })
}

//社区
function getCommunity() {
    $.ajax({
        type: "post",
        url: host + "community/findAll.do",
        xhrFields: {
            withCredentials: true
        },
        success: function (jackson) {
            if (jackson.status == 1) {
                alert(jackson.msg)
            } else if (jackson.status == 0) {
                $("#communityList").html("");
                for (var i = 0; i < jackson.data.length; i++) {
                    $("#communityList").append(
                        "<li class=\"am-nav\" style=\"width: 96%;margin: 2% auto; \">\n" +
                        "        <div class=\"am-u-sm-12\" style=\"background-color: white;padding-top: 3%;padding-bottom: 3%;\">\n" +
                        "            <div class=\"am-u-sm-4\" style=\"padding: 0;height: 66.66px;\">\n" +
                        "                <img src='" + host + jackson.data[i].image + "' alt='照片' class=\"am-img-thumbnail am-radius\" style='width: 83.33%;height: 100%;'>\n" +
                        "            </div>\n" +
                        "\n" +
                        "            <div class=\"am-u-sm-8\" style=\"vertical-align: top;padding-left: 0;\">\n" +
                        "                <h5 style=\"margin-bottom: 1%;font-size: 14px;\">顺路送<span\n" +
                        "                        style=\"float: right;color: #C0C0C0;font-size: 13px;\">" + getLocalTime(jackson.data[i].createTime) + "</span></h5>\n" +
                        "                <a href='communityInfo.html?communityId=" + jackson.data[i].id + "' style='color: black;'><p style=\"margin: 0;font-size: 14px;\">" + jackson.data[i].content + "</p></a>" +
                        "            </div>" +
                        "        </div>\n" +
                        "    </li>"
                    );
                }
            }
        }
    })
}

function getUserCommunity() {
    $.ajax({
        type: "post",
        url: host + "community/findUserCommunity.do",
        xhrFields: {
            withCredentials: true
        },
        async: false,
        success: function (jackson) {
            if (jackson.status == 1) {
                alert(jackson.msg);
                window.location.href = "login.html";
            } else if (jackson.status == 0) {
                $("#userCommunityList").html("");
                for (var i = 0; i < jackson.data.length; i++) {
                    $("#userCommunityList").append(
                        "<li class=\"am-nav\" style=\"width: 96%;margin: 2% auto; \" id='" + jackson.data[i].id + "'>\n" +
                        "        <div class=\"am-u-sm-12\" style=\"background-color: white;padding-top: 3%;padding-bottom: 3%;\" data-id='" + jackson.data[i].id + "'\">\n" +
                        "            <div class=\"am-u-sm-4\" style=\"padding: 0;height: 66.66px;\">\n" +
                        "                <img src='" + host + jackson.data[i].image + "' alt='照片' class=\"am-img-thumbnail am-radius\" style='width: 83.33%;height: 100%;'>\n" +
                        "            </div>\n" +
                        "\n" +
                        "            <div class=\"am-u-sm-8\" style=\"vertical-align: top;padding-left: 0;\">\n" +
                        "                <h5 style=\"margin-bottom: 1%;font-size: 14px;\">顺路送<span\n" +
                        "                        style=\"float: right;color: #C0C0C0;font-size: 13px;\">" + getLocalTime(jackson.data[i].createTime) + "</span></h5>\n" +
                        "                <a href='communityInfo.html?communityId=" + jackson.data[i].id + "' style='color: black;'><p style=\"margin: 0;font-size: 14px;\">" + jackson.data[i].content + "</p></a>" +
                        "            </div>\n" +
                        "        </div>\n" +
                        "        <button type='button' class='am-btn am-btn-sm am-btn-link' style='float: right;outline: none;'>删除</button>" +
                        "</li>"
                    );
                }
            }
        }
    })

}

function searchCommunity() {
    $.ajax({
        type: "post",
        url: host + "community/searchCommunity.do",
        data: {
            content: $("#communityContent").val()
        },
        xhrFields: {
            withCredentials: true
        },
        success: function (jackson) {
            if (jackson.status == 1) {
                alert(jackson.msg)
            } else if (jackson.status == 0) {
                $("#communityList").html("");
                for (var i = 0; i < jackson.data.length; i++) {
                    $("#communityList").append(
                        "<li class=\"am-nav\" style=\"width: 96%;margin: 2% auto; \">\n" +
                        "        <div class=\"am-u-sm-12\" style=\"background-color: white;padding-top: 3%;padding-bottom: 3%;\">\n" +
                        "            <div class=\"am-u-sm-4\" style=\"padding: 0;height: 66.66px;\">\n" +
                        "                <img src='" + host + jackson.data[i].image + "' alt='照片' class=\"am-img-thumbnail am-radius\" style='width: 83.33%;height: 100%;'>\n" +
                        "            </div>\n" +
                        "            <div class=\"am-u-sm-8\" style=\"vertical-align: top;padding-left: 0;\">\n" +
                        "                <h5 style=\"margin-bottom: 1%;font-size: 14px;\">顺路送<span\n" +
                        "                        style=\"float: right;color: #C0C0C0;font-size: 13px;\">" + getLocalTime(jackson.data[i].createTime) + "</span></h5>\n" +
                        "                <p style=\"margin: 0;font-size: 14px;\">" + jackson.data[i].content + "</p>\n" +
                        "            </div>\n" +
                        "        </div>\n" +
                        "    </li>"
                    )
                }
            }
        }
    })
}

function getSingleCommunity(communityId) {
    $.ajax({
        type: "post",
        url: host + "community/findSingle.do",

        data: {
            id: communityId
        },
        xhrFields: {
            withCredentials: true
        },
        success: function (jackson) {
            if (jackson.status == 1) {
                alert(jackson.msg)
            } else if (jackson.status == 0) {
                $("#communityInfo").append(
                    " <div class=\"am-g\">\n" +
                    "   <div class=\"am-u-sm-12\">\n" +
                    "       <div class=\"am-thumbnail\">\n" +
                    "           <img src=" + host + jackson.data.image + " alt=\"\"/>\n" +
                    "           <div class=\"am-thumbnail-caption\">\n" +
                    "               <h3>顺路送</h3>\n" +
                    "               <p>" + jackson.data.content + "</p>\n" +
                    "           </div>\n" +
                    "       </div>\n" +
                    "    </div>\n" +
                    "</div>"
                )
            }
        }
    })
}

function addCommunity(file, communityContent) {
    let flag = ""
    let data = new FormData();
    data.append("file", file);
    data.append("content", communityContent);
    $.ajax({
        type: "post",
        url: host + "community/addCommunity.do",
        data: data,
        async: false,
        processData: false,
        contentType: false,
        xhrFields: {
            withCredentials: true
        },
        success: function (jackson) {
            flag = jackson.data ? "error" : "success";
        }
    });
    return flag;
}

function deleteCommunity(communityId) {
    let msg = ""
    $.ajax({
        type: "post",
        url: host + "community/deleteCommunity.do",
        data: {
            id: communityId
        },
        async: false,
        xhrFields: {
            withCredentials: true
        },
        success: function (jackson) {
            msg = jackson.status ? jackson.msg : jackson.data;
        }
    })
    return msg
}

//订单
function getUserOrder() {
    $.ajax({
        type: "post",
        url: host + "order/findAllOrder.do",
        async: false,
        xhrFields: {
            withCredentials: true
        },
        success: function (jackson) {
            if (jackson.status == 1) {
                alert(jackson.msg)
                window.location.href = "login.html"
            } else if (jackson.status == 0) {
                $("#orderList").html("")
                for (let i = 0; i < jackson.data.length; i++) {
                    var name = getCategory(jackson.data[i].categoryId);
                    $("#orderList").append(
                        "<li class=\"am-u-sm-12 order-nav\" id='" + jackson.data[i].id + "'>" +
                        "   <div href=\"javascript:0;\" class=\"am-u-sm-3\" style=\"padding:0 16px 0 0;\">\n" +
                        "       <div>\n" +
                        "           <img src=\"img/1.png\" alt=\"\" style=\"width: 100%;\">\n" +
                        "       </div>\n" +
                        "   </div>\n" +
                        "   <a class=\"am-u-sm-9\" data-id='" + jackson.data[i].id + "' href='orderInfo.html?orderId=" + jackson.data[i].id + "' style='color: black;line-height: 0.5em;padding: 0;'>" +
                        "       <div style=\"\">\n" +
                        "           <p>\n" +
                        "               物件：<span>" + name + "</span>\n" +
                        "               <span style=\"float: right;margin-right: 10%;\">运费：￥<span>" + jackson.data[i].price + "</span></span>\n" +
                        "           </p>\n" +
                        "           <p>起始地：<span>" + jackson.data[i].pos1 + "</span></p>\n" +
                        "           <p>目的地：<span>" + jackson.data[i].pos2 + "</span></p>\n" +
                        "       </div>\n" +
                        "   </a>\n" +
                        "   <button type='button' class='am-btn am-btn-sm am-btn-link' style='float: right;outline: none;'>删除</button>" +
                        "   <button type='button' id='commentsBtn" + i + "' class='am-btn am-btn-sm am-btn-warning' style='outline: none;'>" +
                        "       <a href='commentsOrder.html?orderId=" + jackson.data[i].id + "' style='color: white;'>评论</a>" +
                        "   </button>" +
                        "</li>"
                    );
                    if (jackson.data[i].status != 1) {
                        $("#commentsBtn" + i).remove()
                    }
                }
            }
        }
    })
}

function getOngoingOrder() {
    $.ajax({
        type: "post",
        url: host + "order/getOngoingOrder.do",
        async: false,
        xhrFields: {
            withCredentials: true
        },
        success: function (jackson) {
            if (jackson.status == 1) {
                if (jackson.msg == "用户未登录，请先登录") {
                    window.location.href = "login.html";
                } else {
                    console.log(jackson.msg);
                }
            } else if (jackson.status == 0) {

            }
        }
    })
}

function getUnpaidOrder() {
    $.ajax({
        type: "post",
        url: host + "order/getUnpaidOrder.do",
        async: false,
        xhrFields: {
            withCredentials: true
        },
        success: function (jackson) {
            if (jackson.status == 1) {
                if (jackson.msg == "用户未登录，请先登录") {
                    window.location.href = "login.html"
                }
            } else if (jackson.status == 0) {
                $("#unpaidOrder").show();
                $("#pos1").attr("disabled",true);
                $("#pos2").attr("disabled",true);
                $("#unpaidOrder").append(
                    "<div class=\"am-u-sm-12\">\n" +
                    "   <p style=\"vertical-align: bottom;border-bottom: 1px solid #f1f1f1;margin: 0;padding-bottom: 2%;\">\n" +
                    "       <img src=\"img/broadcast.png\" style=\"width: 30px;\" alt=\"\">\n" +
                    "       <span style=\"margin-left: 5%;color: black;\">待处理行程</span>\n" +
                    "   </p>\n" +
                    "   <div style=\"padding-top: 5%;\">\n" +
                    "       <div style=\"padding-top: 2%;float: left;\">\n" +
                    "           <img src=\"img/box.png\" alt=\"\" style=\"width: 40px;\">\n" +
                    "       </div>\n" +
                    "\n" +
                    "       <div class=\"am-u-sm-7\" style=\"padding: 0;margin-left: 2%;\">\n" +
                    "           <p style=\"color: black;font-size: 14px;margin-bottom: 5px;\">" + formatDateTime(jackson.data.createTime) + "(出发)</p>\n" +
                    "           <p style=\"font-size: 13px;margin: 0;color: #d9d9d9;\">" + jackson.data.pos1 + "—" + jackson.data.pos2 + "</p>\n" +
                    "       </div>\n" +
                    "       <div style=\"font-size: 18px;padding: 0;line-height: 2.5em;\">\n" +
                    "           <a href='unpaidInfo.html?orderId=" + jackson.data.id + "' style='color: rgb(252,131,62);'>待处理&nbsp;<img src='img/right.png' alt='' style='width: 12px;' /></a>" +
                    "       </div>" +
                    "   </div>" +
                    "</div>"
                );

                $("#pos1").html(jackson.data.pos1);
                $("#pos2").html(jackson.data.pos2);
                $("#category").html(getCategory(jackson.data.categoryId));
                $("#createTime").html(formatDateTime(jackson.data.createTime));
                $("#price").html(jackson.data.price);
            }
        }
    });
}

function getOpenOrder() {
    $.ajax({
        type: "post",
        url: host + "order/getOpenOrder.do",
        async: false,
        xhrFields: {
            withCredentials: true
        },
        success: function (jackson) {
            if (jackson.status == 1) {
                if (jackson.msg == "用户未登录，请先登录") {
                    window.location.href = "login.html";
                } else {
                    console.log(jackson.msg);
                }
            } else if (jackson.status == 0) {
                $("#openOrder").show();
                $("#pos1").attr("disabled",true);
                $("#pos2").attr("disabled",true);
                $("#openOrder").append(
                    "<div class=\"am-u-sm-12\">\n" +
                    "   <p style=\"vertical-align: bottom;border-bottom: 1px solid #f1f1f1;margin: 0;padding-bottom: 2%;\">\n" +
                    "       <img src=\"img/car.png\" style=\"width: 32px;\" alt=\"\">\n" +
                    "       <span style=\"margin-left: 5%;color: black;font-size: 18px;\">我的顺一下</span>\n" +
                    "   </p>" +
                    "   <div style=\"padding-top: 5%;\">\n" +
                    "       <div class=\"am-u-sm-12\" style=\"font-size: 14px;line-height: 0.8em;\">\n" +
                    "           <p>131****0360</p>\n" +
                    "           <p style=\"font-size: 16px;\">" + jackson.data.pos1 + "<span>—></span>" + jackson.data.pos2 + "</p>\n" +
                    "           <p>出发时间：<span" + formatDateTime(jackson.data.createTime) + "</span></p>\n" +
                    "           <p>\n" +
                    "               <div style=\"display: inline-block;font-size: 14px;\">物品种类：<span>" + getCategory(jackson.data.categoryId) + "</span></div>\n" +
                    "               <div style=\"float: right;font-size: 14px;\">重量：<span>10千克以内</span></div>\n" +
                    "           </p>\n" +
                    "           <p>\n" +
                    "               <div style=\"font-size: 16px;\">单价：<span>" + jackson.data.price + "</span>&nbsp;元</div>\n" +
                    "           </p>\n" +
                    "       </div>\n" +
                    "   </div>\n" +
                    "   <button id=\"cancelOrderBtn\" onclick=\"cancelOrder('" + jackson.data.id + "')\" type=\"button\" class=\"am-btn am-btn-sm am-btn-warning\"\n" +
                    "                style=\"float: right;border-radius: 20px;font-size: 18px;letter-spacing: 1px;height: 28px;line-height: 0.5em;outline: none;background-color: rgb(254,103,0);margin-top: 10px;\">\n" +
                    "       取消\n" +
                    "   </button>\n" +
                    "</div>"
                );
            }
        }
    });
}

function getSingleOrder(orderId) {
    $.ajax({
        type: "post",
        url: host + "order/findSingle.do",
        data: {
            id: orderId
        },
        xhrFields: {
            withCredentials: true
        },
        success: function (jackson) {
            if (jackson.status == 1) {
                alert(jackson.msg)
                window.location.href = "login.html";
            } else if (jackson.status == 0) {
                $(".orderId").html(jackson.data.id)
                $(".category").html(getCategory(jackson.data.categoryId));
                $(".pos1").html(jackson.data.carId);
                $(".pos1").html(jackson.data.pos1);
                $(".pos2").html(jackson.data.pos2);
                $(".distance").html(jackson.data.distance);
                $(".price").html(jackson.data.price);
                $(".status").html(getStatusName(jackson.data.status));
                $(".createTime").html(formatDateTime(jackson.data.createTime));
            }
        }
    })
}

function addOrder(category, pos1, pos2, distance, price) {
    $.ajax({
        type: "post",
        url: host + "order/addOrder.do",
        data: {
            categoryId: category,
            pos1: pos1,
            pos2: pos2,
            distance: distance,
            price: price
        },
        xhrFields: {
            withCredentials: true
        },
        success: function (jackson) {
            if (jackson.status == 1) {
                alert(jackson.msg)
            } else if (jackson.status == 0) {
                window.location.href = "index.html";
            }
        }
    })
}

function cancelOrder(orderId) {
    $.ajax({
        type: "post",
        url: host + "order/cancelOrder.do",
        data: {
            id: orderId
        },
        xhrFields: {
            withCredentials: true
        },
        success: function (jackson) {
            if (jackson.status == 1) {
                alert(jackson.msg)
            } else if (jackson.status == 0) {
                $("#openOrder").hide();
                $("#pos1").attr("disabled", false);
                $("#pos2").attr("disabled", false);
            }
        }
    })
}

function deleteOrder(orderId) {
    let msg = ""
    $.ajax({
        type: "post",
        url: host + "order/deleteOrder.do",
        data: {
            id: orderId
        },
        async: false,
        xhrFields: {
            withCredentials: true
        },
        success: function (jackson) {
            msg = jackson.status ? jackson.msg : jackson.data;
        }
    });
    return msg;
}

function payOrder(orderId, price,name) {
    $.ajax({
        type: "post",
        url: host + "alipay/pay.do",
        data: {
            WIDout_trade_no: orderId,
            WIDsubject: "手机支付" + name,
            WIDtotal_amount: price,
            WIDbody: name + "价格" + price
        },
        xhrFields: {
            withCredentials: true
        },
        success: function (jackson) {
            if (jackson.status == 1) {
                alert(jackson.msg)
            } else if (jackson.status == 0) {

            }
        }
    })
}

function commentsOrder(orderId, commentsContent, star) {
    $.ajax({
        type: "post",
        url: host + "order/commentsOrder.do",
        data: {
            content: commentsContent,
            star: star,
            orderId: orderId
        },
        xhrFields: {
            withCredentials: true
        },
        success: function (jackson) {
            if (jackson.status == 1) {
                if (jackson.msg == "用户未登录，请先登录") {
                    window.location.href = "login.html"
                }else {
                    alert(jackson.msg)
                }
            } else if (jackson.status == 0) {
                window.location.href = "me.html"
            }
        }
    })
}

//其它
function getUserIntegral() {
    $.ajax({
        type: "post",
        url: host + "other/findUserIntegral.do",
        xhrFields: {
            withCredentials: true
        },
        success: function (jackson) {
            if (jackson.status == 1) {
                alert(jackson.msg)
            } else if (jackson.status == 0) {
                $(".integral").html(jackson.data.count)
                $(".rank").html(getRank(jackson.data.rankId))
            }
        }
    })
}

function getRank(rankId) {
    let rankName = ""
    $.ajax({
        type: "post",
        url: host + "other/findUserRank.do",
        data: {
            id: rankId
        },
        async: false,
        xhrFields: {
            withCredentials: true
        },
        success: function (jackson) {
            if (jackson.status == 1) {
                alert(jackson.msg)
            } else if (jackson.status == 0) {
                rankName = jackson.data.name;
            }
        }
    });
    return rankName;
}

function getCategory(categoryId) {
    let name = ""
    $.ajax({
        type: "post",
        url: host + "other/findCategoryName.do",
        data: {
            id: categoryId
        },
        xhrFields: {
            withCredentials: true
        },
        async: false,
        success: function (jackson) {
            if (jackson.status == 1) {
                alert(jackson.msg)
            } else if (jackson.status == 0) {
                name = jackson.data.name;
            }
        }
    })
    return name;
}

function getUserComments() {
    $.ajax({
        type: "post",
        url: host + "other/findUserComments.do",
        xhrFields: {
            withCredentials: true
        },
        success: function (jackson) {
            if (jackson.status == 1) {
                alert(jackson.msg)
            } else if (jackson.status == 0) {
                for (let i = 0; i < jackson.data.length; i++) {
                    $("#commentsList").append(
                        "<li style=\"margin-top: 8%;height: 120px;border-bottom: 1px solid #757575;\">\n" +
                        "   <a href=\"javascript:0;\" class=\"am-u-sm-3\" style=\"padding:0 16px 0 0;\">\n" +
                        "       <div>\n" +
                        "           <img src=\"img/1.png\" alt=\"\" style=\"width: 100%;\">\n" +
                        "       </div>\n" +
                        "   </a>\n" +
                        "   <a class=\"am-u-sm-9\" href=\"javascript:0;\"\n" +
                        "                   style='color: black;line-height: 0.5em;padding: 0;'>\n" +
                        "       <div style=\"\">\n" +
                        "           <p>寄件人：<span>name</span></p>\n" +
                        "           <p>星级: <span id='star" + i + "'></span></p>" +
                        "           <p>评论：<span>" + jackson.data[i].content + "</span></p>\n" +
                        "           <p>时间：<span>" + formatDateTime(jackson.data[i].createTime) + "</span></p>\n" +
                        "       </div>\n" +
                        "   </a>\n" +
                        "</li>"
                    );
                    $("#star" + i).raty({readOnly: true, score: jackson.data[i].star})
                }
            }
        }
    })
}

function getCategoryList() {
    $.ajax({
        type: "post",
        url: host + "manage/other/categoryList.do",
        xhrFields: {
            withCredentials: true
        },
        async: false,
        success: function (jackson) {
            if (jackson.status == 1) {
                alert(jackson.msg)
            } else if (jackson.status == 0) {
                $("#categoryOption").show();
                for (let i = 0; i < jackson.data.length; i++) {
                    $("#categoryOption").append(
                        "<option value='" + jackson.data[i].id + "' style='color: black'>" + jackson.data[i].name + "</option>"
                    )
                }
            }
        }
    })
}

function getComenetsInfo(id) {

}

UrlParm = function () { // url参数
    var data, index;
    (function init() {
        data = [];
        index = {};
        var u = window.location.search.substr(1);
        if (u != '') {
            var parms = decodeURIComponent(u).split('&');
            for (var i = 0, len = parms.length; i < len; i++) {
                if (parms[i] != '') {
                    var p = parms[i].split("=");
                    if (p.length === 1 || (p.length === 2 && p[1] === '')) {// p | p=
                        data.push(['']);
                        index[p[0]] = data.length - 1;
                    } else if (typeof(p[0]) === 'undefined' || p[0] === '') { // =c | =
                        data[0] = [p[1]];
                    } else if (typeof(index[p[0]]) === 'undefined') { // c=aaa
                        data.push([p[1]]);
                        index[p[0]] = data.length - 1;
                    } else {// c=aaa
                        data[index[p[0]]].push(p[1]);
                    }
                }
            }
        }
    })();
    return {
        // 获得参数,类似request.getParameter()
        parm: function (o) { // o: 参数名或者参数次序
            try {
                return (typeof(o) === 'number' ? data[o][0] : data[index[o]][0]);
            } catch (e) {
            }
        },
        //获得参数组, 类似request.getParameterValues()
        parmValues: function (o) { // o: 参数名或者参数次序
            try {
                return (typeof(o) === 'number' ? data[o] : data[index[o]]);
            } catch (e) {
            }
        },
        //是否含有parmName参数
        hasParm: function (parmName) {
            return typeof(parmName) === 'string' ? typeof(index[parmName]) != 'undefined' : false;
        },
        // 获得参数Map ,类似request.getParameterMap()
        parmMap: function () {
            var map = {};
            try {
                for (var p in index) {
                    map[p] = data[index[p]];
                }
            } catch (e) {
            }
            return map;
        }
    }
}();

function getLocalTime(obj) {
    var date = new Date(obj);
    var y = 1900 + date.getYear();
    var m = "0" + (date.getMonth() + 1);
    var d = "0" + date.getDate();
    return y + "-" + m.substring(m.length - 2, m.length) + "-" + d.substring(d.length - 2, d.length);
}

function formatDateTime(inputTime) {
    var date = new Date(inputTime);
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    m = m < 10 ? ('0' + m) : m;
    var d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    var h = date.getHours();
    h = h < 10 ? ('0' + h) : h;
    var minute = date.getMinutes();
    var second = date.getSeconds();
    minute = minute < 10 ? ('0' + minute) : minute;
    second = second < 10 ? ('0' + second) : second;
    return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
};

function getStatusName(status) {
    if (status == 2) {
        return "已完成"
    } else if (status == 1) {
        return "未评论"
    } else if (status == 0) {
        return "未接订单"
    } else if (status == -1) {
        return "已取消"
    } else if (status == -2) {
        return "未付款"
    }else {
        return "正在进行"
    }
}